<form class="layui-form">
  <div class="layui-form-item">
    <label class="layui-form-label">图片名称</label>
    <div class="layui-input-inline">
      <input type="text" name="style_name" lay-verify="required" placeholder="专属名称" autocomplete="off"  id="name" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">专属链接</label>
	<div class="layui-input-inline">
      <select name="link_type">
        <option value="">请选择</option>
        <option value="0">指定链接</option>
        <option value="1">分类ID</option>
        <option value="2">商品ID</option>
        <option value="3">路径模式</option>
      </select>
    </div>
    <div class="layui-input-inline">
      <input type="text" name="link_value" lay-verify="required" placeholder="链接值" autocomplete="off"  id="name" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">专属顺序</label>
    <div class="layui-input-inline">
      <input type="text" name="style_order" lay-verify="required" value="0" autocomplete="off" id="desc" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
	<label class="layui-form-label">专属图片</label>
	<div class="layui-input-inline" id="back_img">
		<input type="file" id="upimg" name="back_img" class="layui-upload-file"> 
	</div>
	<div class="layui-input-inline" id="back_img1" value="2" style="display:none;">
		<input id="back_img_str" value="1" type="text" name="back_img1" lay-verify="required" class="layui-input" readonly> 
	</div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">是否启用</label>
    <div class="layui-input-block">
      <input type="checkbox" name="link_active" lay-skin="switch" lay-text="ON|OFF">
    </div>
    <div class="layui-form-mid layui-word-aux"></div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="user">添加</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
  
</form>
<script>
layui.use(['upload','form', 'layedit', 'laydate'], function(){
var form = layui.form()
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate
  ,upload  = layui.upload
  ,$ = layui.jquery;
  
	  form.on('submit(user)', function(data){
		  
	    var userInfo = data.field;
	    
		var url = "{:U('Style/add')}";
		$.post(url,userInfo,function(data){
        	//alert(data);
        	//return;
			if(data.status == 'error'){
				  layer.msg(data.msg,{icon: 5});//失败的表情
				  return;
			  }else if(data.status == 'success'){
				  layer.msg(data.msg, {
					  icon: 6,//成功的表情
					  time: 1000 //2秒关闭（如果不配置，默认是3秒）
					}, function(){
					   location.reload();
					}); 
			  }
		})
	    return false;//阻止表单跳转
	  });
      
      //查看图片
	$(document).delegate('#back_img_str','click',function(){
		layer.open({
  			title: '查看图片'
  			,content: '<img src="'+this.value+'">'
		});   
	});
	layui.upload({
  		url: "{:U('Style/upload')}"
		,ext: 'jpg'
  		,success: function(res){
        	if(res.code==200){
            	$('#back_img').remove();
				$('#back_img1').show();
				$('#back_img_str').val(res.name);
            }
            if(res.code==400){
            	layer.msg(res.msg,{icon: 5});//失败的表情
				return;
            }
  		}
	});
  form.render(); 
  });
  
</script>